package com.galudisu.handsonic.modules.system.dao;

import com.galudisu.handsonic.modules.system.domain.Organization;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

/**
 * @author Barudisshu
 */
@Repository
public interface OrganizationDao extends JpaRepository<Organization, String> {

    @Query("select o from Organization o where o.id <> :#{#organization.id}")
    List<Organization> findAllWithExclude(@Param("organization") Organization excludeOrganization);

    @Query("update Organization o set o.parentId = :#{#target.id} where o.id = :#{#source.id}")
    void move(Organization source, Organization target);

    @Query("select o.name from Organization o where o.id in (?1)")
    List<String> findWithContain(Collection<String> organizationIds);
}
